/**
 * @author YanYeek
 * @time 2021/06/01
 * @impact 用于控制音乐音效模块
 */
module.exports = (function () {
	let dj_module = {};
	dj_module.bgMusic = null;

	/** 播放背景音乐 */
	dj_module.playMusic = (clip, loop = false) => {
		if (dj_module.bgMusic) {
			cc.audioEngine.stopMusic(dj_module.bgMusic);
		}
		cc.audioEngine.play(clip, loop);
		dj_module.bgMusic = clip;
	};
	/** 停止播放背景音乐 */
	dj_module.stopMusic = () => {
		cc.audioEngine.stopMusic(dj_module.bgMusic);
	};

	/** 控制音乐的音量 */
	dj_module.setMusicVolume = function (volume) {
		console.log("设置音量"+volume);
		cc.audioEngine.setMusicVolume(volume);
	};

	/** 播放音效 */
	dj_module.playEffect = (clip, volume = 1, loop = false) => {
		cc.audioEngine.playEffect(clip, loop);
		cc.audioEngine.setEffectsVolume(volume);
	};

	return dj_module;
})();
